<?php

/**
 * Description of action
 *
 * @author johannes
 */
class action {

    public $c;

    public function output($input) {
        echo $input;
    }

    public function take($input) {
        $input = explode(" ", $input);


        $word = $input[0];
        $query = "SELECT id FROM words WHERE word='" . $word . "'";
        $result = mysqli_query($this->c, $query);

        while ($rows = mysqli_fetch_assoc($result)) {
            $word_id = $rows['id'];
        }
        switch ($word_id) {
            case 3: if ($this->show($input)
                    )return true; break;
            case 8: if ($this->attack($input)
                    )return true; break;
        }


        $query = "SELECT * FROM parameter WHERE word_id =" . $word_id . " ORDER BY `rel_pos`";
        $result = mysqli_query($this->c, $query);

        while ($rows = mysqli_fetch_assoc($result)) {
            $rel_pos = $rows['rel_pos'];
            $required_type_id = $rows['required_type_id'];
        }
    }

    public function attack($input) {
        $count = count($input);
        $victim = $input[1];
        if ($input[2] != "using") {
            return false;
        }
        $tool = $input[3];


        for ($i = 0; $i < $count; $i++) {
            
        }
    }

    public function show($input) {
        $query1 = "SELECT id FROM words WHERE word ='" . $input[1] . "'AND id =4";
        $query2 = "SELECT id FROM places WHERE name ='" . $input[1] . "'";
        $query3 = "SELECT id FROM thing_types WHERE name ='" . $input[1] . "'";
        if (mysqli_num_rows(mysqli_query($this->c,$query1))) {
            echo "Your Pocket:<br><ul>";
            $query="SELECT * FROM things WHERE owner=".$_SESSION['id'];
            $result=mysqli_query($this->c,$query);
            while($thing=mysqli_fetch_assoc($result)){
                $name_query="SELECT name FROM thing_types WHERE id=".$thing['type_id'];
                $name_result=mysqli_query($this->c, $name_query);
                while($thing_type=mysqli_fetch_assoc($name_result)){
                    $name=$thing_type['name'];
                }
                echo "<li>".$name."</li>";
            }

        } elseif (mysqli_num_rows(mysqli_query($this->c,$query2))) {
            echo "A PLACE";
        } elseif (mysqli_num_rows(mysqli_query($this->c,$query3))) {
            echo "A THING";
        }
    }

}

?>
